<script setup lang='ts'>
import { inject, onBeforeUnmount, ref } from 'vue';
import { createVueDisposer, toVR } from 'vue-xe2-plugin/dist-node/components/xe2/tools';
import { UeViewer } from 'xbsj-xe2/dist-node/xe2-ue-objects';
import Button from '../../components/Button.vue';
import RightList from '../../components/RightList.vue';
import { XbsjEarthUi } from '../../scripts/xbsjEarthUi';
import ViewManager from "./cameraViews/ViewManager.vue";
const xbsjEarthUi = inject('xbsjEarthUi') as XbsjEarthUi

const { viewsManager } = xbsjEarthUi;
const customRef = ref(false)
const d = createVueDisposer(onBeforeUnmount)
const ueIsShow = toVR<boolean>(d, [xbsjEarthUi, 'ueIsShow'])
const { cameraViewsManager } = xbsjEarthUi

const loopplying = toVR<boolean>(d, [cameraViewsManager, 'playing'])//视角数组

const changeToMap = () => {
    const viewer = xbsjEarthUi.activeViewer
    if (!viewer) return
    viewer.changeToMap()
    xbsjEarthUi.roamMode = 'Map'
}
const sceneList = [
    {
        zh: '全球',
        class: 'global',
        func: () => {
            changeToMap()
            viewsManager.globalView.flyIn()
        },
        icon: 'quanqiu',
        leftButton: true,
    },
    {
        zh: '中国',
        class: 'china',
        func: () => {
            changeToMap()
            viewsManager.cnView.flyIn()
        },
        icon: 'zhongguohangzheng',
        leftButton: false,
    }
]
const startView = () => {
    const viewer = xbsjEarthUi.activeViewer
    if (!viewer) return
    if (viewer.innerViewer instanceof UeViewer) {
        //@ts-ignore
        viewer.innerViewer.defaultCameraFlyIn(1)
    }
}
const viewerManager = () => {
    changeToMap()
    customRef.value = !customRef.value
    if(!customRef.value){
        loopplying.value=false
    }
}
</script>

<template>
    <RightList :title="'视角'" :isTop="true">
        <Button v-for="item in sceneList" :name="item.icon" :content="item.zh" :click="item.func"
            :left-button="item.leftButton"></Button>
        <Button :name="'zidingyi'" :content="'自定义'" :click="viewerManager" :actived="customRef"
            :left-button="true"></Button>
        <Button :name="'chushi'" :content="'初始'" :click="startView" v-if="ueIsShow"></Button>
        <ViewManager v-if="customRef"></ViewManager>
    </RightList>
</template>